<?php
// 自营控制器
class Controller_WWW_Ziying extends Controller_WWW_Template
{
    public function __construct ($req, $res)
   {
       $this->template = "smarty:www/ziying/detail";
       parent::__construct($req, $res);
   }
   // 自营项目详情
    public function action_detail ($zyId)
   {
       $ziying  = new Ziying($zyId);
       $detail = $ziying->detail();
       //屏蔽今天之前的服务时间
       $frees = explode(',', $detail['freetimeDays']);
       $days = array();
	foreach ($frees as $d)
	{
          $d = trim($d);
	  if (! empty($d))
	  $days[] = $d;
	}
	$today = strtotime(date("Y-m-d"));
	foreach ($days as $k => $day)
	{
	  $t = strtotime($day);	
	  if ($t < $today)
	  unset($days[$k]);
	}
       $detail['freetimeDays']=$days;
       //获取目的地
       $detail['city']=explode('|',$detail['city']);
       foreach($detail['city'] as $k => &$v)
       {
	  if(!empty($v)){
	     trim($v);
	  }else{unset($detail['city'][$k]);}		
       }
       //获取推荐理由
       $detail['recommend']=explode(';',$detail['recommend']);
       foreach($detail['recommend'] as $k => &$v)
       {
	  if(!empty($v)){
	     trim($v);
	  }else{unset($detail['recommend'][$k]);}
				
       }
       $this->template->set('ziying', $detail);
       //获取每日剩余的库存量
       $leftperson=$ziying->getLeftPersonOfDays();
       $this->template->set('leftperson', $leftperson);
       //获取今日之后每日价格和最低价格 
       $pofdays=$ziying->getPriceOfDays();
       $this->template->set('priceofdays', $pofdays);
       if(!empty($pofdays)){
       $minprice=min($pofdays);
       $this->template->set('minprice', $minprice);
       }
    }
    //获取产品介绍
    public function action_get_product_description(){
       $post=$this->request->post();
       $zyId=Arr::get($post, 'zyId');
       $ziying  = new Ziying($zyId);
       $detail = $ziying->detail();

       $comments = Comments::getActivityOrTrackComments($zyId,'ZIYING',5,0);
       foreach($comments as &$v){
          $v['tourist_pic'] = explode(';',$v['tourist_pic']);
       }
       $html = View::factory('smarty:www/ziying/widget_description')
	       ->set("comments",$comments)
	       ->set('counts', count($comments))
	       ->set('ziying',$detail)
	       ->render();
       echo json_encode($html);exit;
    }
}
